/*
* © 2010 Autodata Solutions Company. All Rights Reserved
* This source code is the confidential and proprietary information of Autodata Solutions Company.
* The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
* without the prior written consent of Autodata Solutions Company.
*
* File: net/autodata/compare/widgets/CompetitorToolbar.js
* Purpose: Provides custom implimintation of the compare's select competitor toolbar.
*
* Namespace: net.autodata.compare
* Requires:ExtJS,
*          ASC library - net/autodata/ascjs-ext-debug.js
*/

Ext.ns('net.autodata.compare.CompetitorToolbar');
(function() {
    /**
    * The class does not have a public constructor
    * @class CompetitorToolbarStore
    * @namespace net.autodata.compare.data
    */
    var Store = Ext.extend(Ext.data.Store, {
        constructor: function(cfg) {
            this.addEvents({
                'updatecompetitor': true
            });

            cfg = cfg || {};

            Ext.apply(cfg, {
                autoLoad: false,
                reader: new Ext.data.JsonReader({
                    idProperty: 'acode',
                    root: 'rows',

                    fields: [
						    { name: 'acode' }
					    ]
                })
            });

            Store.superclass.constructor.call(this, cfg);
        }
    });
    /**
    * Custom toolbar plugin for grid top toolbar
    * @class ResultToolbar
    * @extends Ext.Toolbar
    * @namespace net.autodata.compare 
    */
    var Toolbar = Ext.extend(Ext.Toolbar, {
        component: undefined,
        view: undefined,
        selectedIndex: undefined,
        store: undefined,

        forceLayout: true,
        width: 788,
        cls: 'compare-toolbar',
        height: 36,

        constructor: function(cfg) {
            cfg = cfg || {};

            var storeCfg = cfg.storeCfg;
            delete cfg.storeCfg;

            this.store = new Store(storeCfg);

            Toolbar.superclass.constructor.call(this, cfg);
        },

        initComponent: function() {
            Toolbar.superclass.initComponent.call(this, arguments);
            var view = this.getView();
            view.init(this);
        },

        getView: function() {
            if (!this.view) {
                this.view = new net.autodata.AdvantagesToolbarView(this.viewCfg);
            }

            return this.view;
        },

        getStore: function() {
            if (!this.store) {
                this.store = new Store(this.storeCfg);
            }

            return this.store;
        },

        getParentComponent: function() {
            return this.component;
        },

        /**
        * Toolbar's plugin initilaization function.
        * @method init
        * @param {net.autodata.compare.Advantages} grid
        */
        init: function(component) {
            this.component = component;
        },

        //Event Handlers

        /**
        * Toolbars on destroy event handler.
        * @method onDestroy
        * @private
        */
        onDestroy: function() {
            //clean up to ensure no function references are left behind
            //to cause a memmory leak
        }
    });

    net.autodata.compare.CompetitorToolbar = Toolbar;
})();
